﻿Imports System.Data
Imports System.Data.SqlClient
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL

Public Class CruceFletesDALC
    Public Function CruceFlete(ByVal objCruceFlete As CruceFletesBE) As List(Of CruceFletesBE)

        Dim sqlListar As String
        Dim lstCruceFletes As New List(Of CruceFletesBE)
        Dim objCruceFletesBE As CruceFletesBE = Nothing
        Dim arrSqlParameter(4) As SqlParameter
        Dim ds As DataSet
        Dim dt As DataTable

        Dim objDatos As New AccesoDatos()
        Dim blnExito As Boolean
        Dim strMensaje As String = String.Empty
        Dim intI As Integer = 0

        Try

            sqlListar = "up_CruceFletes_Consultar"

            arrSqlParameter(0) = New SqlParameter("@KVJE", System.Data.SqlDbType.VarChar)
            arrSqlParameter(0).Value = objCruceFlete.Kvje

            arrSqlParameter(1) = New SqlParameter("@CSNE", System.Data.SqlDbType.VarChar)
            arrSqlParameter(1).Value = objCruceFlete.Csne

            arrSqlParameter(2) = New SqlParameter("@KSER", System.Data.SqlDbType.VarChar)
            arrSqlParameter(2).Value = objCruceFlete.Serv

            arrSqlParameter(3) = New SqlParameter("@KPTO", System.Data.SqlDbType.VarChar)
            arrSqlParameter(3).Value = objCruceFlete.Pto

            arrSqlParameter(4) = New SqlParameter("@NRBL", System.Data.SqlDbType.VarChar)
            arrSqlParameter(4).Value = objCruceFlete.Nume


            ds = objDatos.DevuelveDataSet(sqlListar, blnExito, strMensaje, arrSqlParameter)
            dt = ds.Tables(0)

            If dt.Rows.Count > 0 Then

                While intI < dt.Rows.Count
                    objCruceFletesBE = New CruceFletesBE()
                   
                    objCruceFletesBE.Kvje = dt.Rows(intI).ItemArray(0).ToString
                    objCruceFletesBE.Kbli = dt.Rows(intI).ItemArray(1).ToString
                    objCruceFletesBE.Nume = dt.Rows(intI).ItemArray(2).ToString
                    objCruceFletesBE.Pto = dt.Rows(intI).ItemArray(3).ToString
                    objCruceFletesBE.Serv = dt.Rows(intI).ItemArray(4).ToString
                    objCruceFletesBE.Csne = dt.Rows(intI).ItemArray(5).ToString
                    objCruceFletesBE.KTarifa = dt.Rows(intI).ItemArray(6).ToString
                    objCruceFletesBE.Tarifa = dt.Rows(intI).ItemArray(7).ToString
                    objCruceFletesBE.UnidadMedida = dt.Rows(intI).ItemArray(8).ToString
                    objCruceFletesBE.Cant = dt.Rows(intI).ItemArray(9).ToString
                    objCruceFletesBE.FleteActual = dt.Rows(intI).ItemArray(10).ToString
                    objCruceFletesBE.FleteTarifa = dt.Rows(intI).ItemArray(11).ToString
                    objCruceFletesBE.Diferencia = dt.Rows(intI).ItemArray(12).ToString
                    intI = intI + 1

                    lstCruceFletes.Add(objCruceFletesBE)
                End While
            End If
        Catch ex As Exception
            MsgBox(ex.Message, vbCritical, "Error del sistema")
            Return Nothing
            Exit Function
        End Try

        Return lstCruceFletes
    End Function

End Class
